home *** CD-ROM | disk | FTP | other *** search
/ Champak 106 / Vol 106.iso / games / rain_for.swf / scripts / __Packages / DiegoWorld.as < prev    next >
Encoding:
Text File  |  2010-04-12  |  8.4 KB  |  306 lines

  1. class DiegoWorld implements smashing.World
  2. {
  3.    var location;
  4.    var oBuildings;
  5.    var oCitizens;
  6.    var oGerms;
  7.    var oPlayer;
  8.    var mcDraw;
  9.    var mcGround;
  10.    var backbg;
  11.    var lives;
  12.    var level;
  13.    var score;
  14.    var cTimeRatio;
  15.    var nDistRatio;
  16.    var aCritters;
  17.    var nTime;
  18.    var moveView;
  19.    var endCheck;
  20.    var aCritterList;
  21.    var aPlacement;
  22.    var howFar;
  23.    static var target;
  24.    var nFullTime = 185;
  25.    var cTime = 0;
  26.    var startTime = 0;
  27.    var nTimeDec = 0;
  28.    var nLowerTimeLimit = 45;
  29.    var nDist = 15000;
  30.    var germReq = 10;
  31.    var timeBonus = 10;
  32.    var playerOffset = 100;
  33.    var nPanic = 0.065;
  34.    var totalCritters = 5;
  35.    var cIdle = 0;
  36.    var nIdle = 5;
  37.    function DiegoWorld(loc)
  38.    {
  39.       DiegoWorld.target = this;
  40.       this.location = loc;
  41.       this.oBuildings = new BuildingHandler(this.location.mcBuildingHolder);
  42.       this.oBuildings.oWorld = this;
  43.       this.oCitizens = new CitizenHandler(this.location.mcCitizens);
  44.       this.oCitizens.oBuildings = this.oBuildings;
  45.       this.oGerms = new GermHandler(this.location.mcGermHolder);
  46.       this.oBuildings.oGerms = this.oGerms;
  47.       this.oPlayer = this.location.mcPlayer;
  48.       this.oPlayer.setBuilding(this.oBuildings,this.oCitizens,this.oGerms);
  49.       this.oPlayer.setShadow(this.location.mcShadow);
  50.       this.oPlayer.oWorld = this;
  51.       this.oPlayer.camera = loc.mcCamera;
  52.       this.mcDraw = loc.mcDraw;
  53.       this.mcGround = loc.mcGround;
  54.       this.backbg = loc.backbg;
  55.       smashing.Menu.watchProp(this,"score","text");
  56.       smashing.Menu.watchProp(this,"cTimeRatio","frameMeter");
  57.       this.lives = 3;
  58.       this.level = 1;
  59.       this.score = 0;
  60.       this.cTimeRatio = 0;
  61.       this.nDistRatio = 0;
  62.       this.aCritters = ["jaguar","marmoset","butterfly","macaw","frog","anaconda","kinkajou","sloth"];
  63.    }
  64.    function onEnter()
  65.    {
  66.    }
  67.    function onExit()
  68.    {
  69.    }
  70.    function onPlay()
  71.    {
  72.    }
  73.    function onPause()
  74.    {
  75.    }
  76.    function update(nElapsed)
  77.    {
  78.       if(nElapsed > 0.06)
  79.       {
  80.          nElapsed = 0.06;
  81.       }
  82.       this.cTime += nElapsed;
  83.       this.cTimeRatio = 1 - this.cTime / this.nTime;
  84.       this.mcDraw.clear();
  85.       this.oCitizens.setRatio(0);
  86.       this.oCitizens.update(nElapsed);
  87.       this.oGerms.update(nElapsed);
  88.       this.oPlayer.update(nElapsed);
  89.       this.moveView(nElapsed);
  90.       this.nDistRatio = smashing.Viewport.x / this.nDist;
  91.       this.endCheck();
  92.       this.oPlayer.render();
  93.       this.oGerms.render();
  94.       this.oCitizens.render();
  95.       this.oBuildings.render();
  96.       this.mcGround.render();
  97.       updateAfterEvent();
  98.    }
  99.    function newGame()
  100.    {
  101.       this.startLevel();
  102.       this.level = 1;
  103.       this.score = 0;
  104.    }
  105.    function startLevel()
  106.    {
  107.       this.backbg.gotoAndStop((this.level - 1) % 3 + 1);
  108.       this.aCritterList = smashing.Misc.rndArray(this.aCritters);
  109.       _global.mcRoot.mcMenu.setCrittersReq(this.aCritterList);
  110.       var _loc4_ = -1;
  111.       var _loc3_ = 0;
  112.       while(_loc3_ < 5)
  113.       {
  114.          if(this.aCritterList[_loc3_] == "sloth")
  115.          {
  116.             _loc4_ = _loc3_;
  117.             break;
  118.          }
  119.          _loc3_ = _loc3_ + 1;
  120.       }
  121.       if(_loc4_ == -1)
  122.       {
  123.          _loc4_ = Math.floor(Math.random() * 5);
  124.       }
  125.       var _loc5_ = [1,1,0,0];
  126.       _loc5_ = smashing.Misc.rndArray(_loc5_);
  127.       this.aPlacement = [];
  128.       _loc3_ = 0;
  129.       while(_loc3_ < 5)
  130.       {
  131.          if(_loc3_ == _loc4_)
  132.          {
  133.             this.aPlacement.push(2);
  134.          }
  135.          else
  136.          {
  137.             this.aPlacement.push(_loc5_.pop());
  138.          }
  139.          _loc3_ = _loc3_ + 1;
  140.       }
  141.       this.location.bg.gotoAndStop((this.level - 1) % 3 + 1);
  142.       this.location.street.gotoAndStop((this.level - 1) % 3 + 1);
  143.       this.howFar = 0;
  144.       smashing.Viewport.reset();
  145.       this.oBuildings.reset(this.level);
  146.       this.oPlayer.reset();
  147.       this.oPlayer.render();
  148.       this.mcGround.y = BuildingHandler.floor - 200;
  149.       this.cTime = this.startTime;
  150.       this.oCitizens.reset();
  151.       this.oCitizens.setLevel(this.level);
  152.       this.oGerms.reset();
  153.       this.moveView = this.moveViewGame;
  154.       this.endCheck = this.endCheckGame;
  155.       this.cTime = this.startTime;
  156.       this.cTimeRatio = 0;
  157.       this.nTime = Math.max(this.nFullTime - this.nTimeDec * this.level,this.nLowerTimeLimit);
  158.       this.nDistRatio = 0;
  159.       this.update(0);
  160.    }
  161.    function endLevelPrep()
  162.    {
  163.       this.endCheck = this.endCheckEnd;
  164.       this.oBuildings.addHome();
  165.    }
  166.    function endLevel()
  167.    {
  168.       _global.mcRoot.mcMusic.oSound.stop();
  169.       _global.mcRoot.mcMenu.nLevel = this.level;
  170.       if(this.cTimeRatio <= 0)
  171.       {
  172.          _global.mcRoot.mcMenu.show("noTime");
  173.       }
  174.       else if(this.level >= 3)
  175.       {
  176.          var _loc4_ = this.nDistRatio - this.cTimeRatio;
  177.          var _loc3_ = Math.floor(_loc4_ * this.timeBonus);
  178.          smashing.Menu.target.timeBonus = _loc3_;
  179.          smashing.Menu.target.oldScore = this.score;
  180.          this.score += _loc3_;
  181.          smashing.Menu.target.newScore = this.score;
  182.          this.endGame();
  183.       }
  184.       else
  185.       {
  186.          _loc4_ = this.nDistRatio - this.cTimeRatio;
  187.          _loc3_ = Math.floor(_loc4_ * this.timeBonus);
  188.          smashing.Menu.target.timeBonus = _loc3_;
  189.          smashing.Menu.target.oldScore = this.score;
  190.          this.score += _loc3_;
  191.          smashing.Menu.target.newScore = this.score;
  192.          _global.mcRoot.mcMenu.show("levelEnd");
  193.          this.level = this.level + 1;
  194.       }
  195.    }
  196.    function endGame()
  197.    {
  198.       _global.mcRoot.finalScore = this.score;
  199.       _global.mcRoot.mcMenu.show("gameEnd");
  200.    }
  201.    function reset()
  202.    {
  203.       this.cTime = this.startTime;
  204.    }
  205.    function moveViewGame(nElapsed)
  206.    {
  207.       smashing.Viewport.y = this.oPlayer.y;
  208.       var _loc4_ = BuildingHandler.floor - smashing.Viewport.halfHeight + 15;
  209.       if(smashing.Viewport.y > _loc4_)
  210.       {
  211.          smashing.Viewport.y = _loc4_;
  212.       }
  213.       else
  214.       {
  215.          var _loc5_ = BuildingHandler.ceiling + smashing.Viewport.halfHeight;
  216.          if(smashing.Viewport.y < _loc5_)
  217.          {
  218.             smashing.Viewport.y = _loc5_;
  219.          }
  220.       }
  221.       var _loc3_ = this.oPlayer.x + this.playerOffset;
  222.       if(_loc3_ > smashing.Viewport.startX)
  223.       {
  224.          smashing.Viewport.x = _loc3_;
  225.       }
  226.       else
  227.       {
  228.          smashing.Viewport.x = smashing.Viewport.startX;
  229.       }
  230.       var _loc2_ = BuildingHandler.homeLimit;
  231.       if(_loc2_ != undefined)
  232.       {
  233.          if(smashing.Viewport.x > _loc2_)
  234.          {
  235.             smashing.Viewport.x = _loc2_;
  236.          }
  237.       }
  238.       if(smashing.Viewport.x > this.howFar)
  239.       {
  240.          this.howFar = smashing.Viewport.x;
  241.       }
  242.    }
  243.    function moveViewEnd(nElapsed)
  244.    {
  245.       smashing.Viewport.y = this.oPlayer.y;
  246.       var _loc4_ = BuildingHandler.floor - smashing.Viewport.halfHeight + 15;
  247.       if(smashing.Viewport.y > _loc4_)
  248.       {
  249.          smashing.Viewport.y = _loc4_;
  250.       }
  251.       else
  252.       {
  253.          var _loc5_ = BuildingHandler.ceiling + smashing.Viewport.halfHeight;
  254.          if(smashing.Viewport.y < _loc5_)
  255.          {
  256.             smashing.Viewport.y = _loc5_;
  257.          }
  258.       }
  259.       var _loc3_ = this.oPlayer.x + this.playerOffset;
  260.       if(_loc3_ - smashing.Viewport.x > 0)
  261.       {
  262.          smashing.Viewport.x = _loc3_;
  263.       }
  264.       var _loc2_ = BuildingHandler.home;
  265.       var _loc6_ = _loc2_.x + _loc2_._width - smashing.Viewport.halfWidth;
  266.       if(smashing.Viewport.x > _loc6_)
  267.       {
  268.          smashing.Viewport.x = _loc6_;
  269.       }
  270.    }
  271.    function endCheckGame()
  272.    {
  273.       if(this.cTimeRatio <= 0)
  274.       {
  275.          this.endLevel();
  276.       }
  277.       if(smashing.Viewport.x >= this.nDist)
  278.       {
  279.          this.endLevelPrep();
  280.       }
  281.    }
  282.    function endCheckEnd()
  283.    {
  284.       if(this.cTimeRatio <= 0)
  285.       {
  286.          this.endLevel();
  287.       }
  288.       if(this.oPlayer.hitTest(BuildingHandler.home.mcHitArea))
  289.       {
  290.          if(this.oPlayer.aCritters.length >= this.totalCritters)
  291.          {
  292.             this.endLevel();
  293.          }
  294.          else if(_global.mcRoot.mcFillBook._currentframe == 1)
  295.          {
  296.             _global.mcRoot.mcFillBook.bPlayed = true;
  297.             _global.mcRoot.mcFillBook.gotoAndPlay(2);
  298.          }
  299.       }
  300.    }
  301.    static function addScore(nScore)
  302.    {
  303.       DiegoWorld.target.score += nScore;
  304.    }
  305. }
  306.